package com.huan.social.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.web.ProviderSignInUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.context.request.ServletWebRequest;

import javax.servlet.http.HttpServletRequest;

/**
 * 测试控制器
 *
 * @author huan.fu
 * @date 2018/9/26 - 10:47
 */
@Controller
@Slf4j
public class DemoController {

	@Autowired
	private ProviderSignInUtils providerSignInUtils;

	@GetMapping("login")
	public String login() {
		return "login";
	}

	@GetMapping("/index")
	public String index(HttpServletRequest request, Model model) {
		Connection<?> connection = providerSignInUtils.getConnectionFromSession(new ServletWebRequest(request));
		log.info("connection info:[{}]", connection);
		model.addAttribute("connection", connection);

		// 执行一个简答的注册，及向 UserConnection表中插入一条数据 providerSignInUtils.doPostSignUp("业务系统userId", new ServletWebRequest(request));

		return "index";
	}

}
